﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace MouseExtender.Logic.Converters
{
	[ValueConversion(typeof(double), typeof(string))]
	public class DoubleToTimeSpanTextConverter : IValueConverter
	{
		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			TimeSpan interval = TimeSpan.FromMinutes((double)value);
			string intervalAsString = "ZZ..zz..";
			if (interval.TotalDays < 1)
				intervalAsString = string.Format("{0:D2}:{1:D2}:{2:D2}", interval.Hours, interval.Minutes, interval.Seconds);

			return intervalAsString;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}

		#endregion
	}
}